# == Schema Information
# Schema version: 20090415123829
#
# Table name: topics
#
#  id         :integer(4)      not null, primary key
#  forum_id   :integer(4)
#  user_id    :integer(4)
#  title      :string(255)
#  body       :text
#  type       :integer(4)
#  created_at :datetime
#  updated_at :datetime
#
class Topic < ActiveRecord::Base
  belongs_to :forum
  has_many :posts
  belongs_to :user
  
  validates_presence_of :title
  
  def last_post_info
    p = posts.find :first, :order => "created_at desc"
    if p
      "由#{p.user.login} 在 #{time_ago_in_words_cn p.created_at}前发布 "
    else
      "一般人看不见这个的。内容空！"
    end
  end
  
  def last_post
    p = posts.find :first, :order => "created_at desc"    
  end
  
end
